package itheima.com.demo;

import java.io.*;
import java.net.Socket;

public class SocketDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",2222);

        OutputStream os = socket.getOutputStream();
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("WorkDemo\\img\\1.jpg"));

        BufferedOutputStream bos = new BufferedOutputStream(os);

        int a;
        while ((a=bis.read())!=-1){
            bos.write((char)a);
        }

        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        String line;
        while((line=br.readLine())!=null){
            System.out.println(line);
        }

        br.close();
        bis.close();
        socket.close();
    }
}
